#include<iostream>
#include"newton.h"

class RungeFunction : public FunctionBase
    {
    public:
        double operator()(double x) {
            return 1.0 / (1 + 25 * x * x);
        }
    };
int main(void){
    

    double a1[100], a2[100], a3[100], a4[100];
    for (int i = 0; i < 5; i++){
        a1[i] = cos((2 * i + 1) * acos(-1) / 10.0);
    }
    for (int i = 0; i < 10; i++){
        a2[i] = cos((2 * i + 1) * acos(-1) / 20.0);
    }
    for (int i = 0; i < 15; i++){
        a3[i] = cos((2 * i + 1) * acos(-1) / 30.0);
    }
    for (int i = 0; i < 20; i++){
        a4[i] = cos((2 * i + 1) * acos(-1) / 40.0);
    }

    RungeFunction f;
    NewtonInterpolator<RungeFunction> interpolator1(a1, 5, f);
    NewtonInterpolator<RungeFunction> interpolator2(a2, 10, f);
    NewtonInterpolator<RungeFunction> interpolator3(a3, 15, f);
    NewtonInterpolator<RungeFunction> interpolator4(a4, 20, f);

    double* z1 = interpolator1.getCoefficients();
    double* z2 = interpolator2.getCoefficients();
    double* z3 = interpolator3.getCoefficients();
    double* z4 = interpolator4.getCoefficients();

    std::cout << "展示n=20时多项式的零点：" << ' ';
    for (int i=0; i < 20; i++){
        std::cout << a4[i] << ' ';
    }
    std::cout << "\n展示n=20时多项式的系数：" << ' ';
    for (int i=0; i < 19; i++){
        std::cout << z4[i] << ' ';
    }
    std::cout << z4[19] << std::endl;
    std::cout << ' ' << std::endl;
    std::cout << ' ' << std::endl;

    return 0;
}
